package com.bidevalution.controller.api;

import com.bidevalution.business.service.BeSummaryService;
import com.bidevalution.dao.entity.BeSummary;
import com.qtp.core.model.Response;
import com.qtp.core.util.DateUtil;
import com.qtp.core.util.GsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description 汇总信息
 * @Date        2020-03-25 14:56
 * @Author      lhl
 */
@Log4j2
@RestController
@Api("评审意见汇总")
@RequestMapping("/beSummary")
public class BeSummaryController {

    @Autowired
    private BeSummaryService beSummaryService;

    /**
     * 获取评审意见汇总页面列表数据
     */
    @ApiOperation(value = "获取评审意见汇总页面列表数据", response = Response.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sectionId", value = "标段信息主键", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "sectionStepId", value = "环节id", dataType = "String", paramType = "query", required = true),
    })
    @GetMapping(value = "/getSummaryInfo")
    public Response<Map<String, Object>> getSummaryInfo(@RequestParam("sectionId") String sectionId,@RequestParam("sectionStepId") String sectionStepId) {
        try {
            return Response.ok(beSummaryService.getSummaryInfo(sectionId,sectionStepId));
        }catch (Exception e){
            log.error("LOG[]getSummaryInfo[]{},error={},params={}","获取评审意见汇总页面列表数据异常", GsonUtil.toJsonWithGson(e),GsonUtil.toJsonWithGson(sectionId)+";"+GsonUtil.toJsonWithGson(sectionStepId));
            return Response.fail(GsonUtil.toJsonWithGson(e));
        }
    }
    /**
     * 修改汇总意见
     */
    @ApiOperation(value = "修改汇总意见", response = Response.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "summaryId", value = "主键", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "remark", value = "评标组长意见汇总信息", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "type", value = "类型1:优势2:不足", dataType = "Integer", paramType = "query", required = true),
    })
    @PostMapping(value = "/updateSummaryInfo")
    public Response<Map<String, Object>> updateSummaryInfo(
            @RequestParam("summaryId") String summaryId,
            @RequestParam("remark") String remark,
            @RequestParam("type") int type
    ) {
        BeSummary beSummary = new BeSummary();
        beSummary.setSeqId(summaryId);
        beSummary.setUpdateTime(DateUtil.getCurrentDateStr(DateUtil.PT2));
        if (type == 1){
            beSummary.setMerit(remark);
        }else if (type == 2){
            beSummary.setDeficiency(remark);
        }else {
            return Response.fail("参数错误！");
        }
        beSummaryService.updateSummaryInfo(beSummary);
        return Response.ok();
    }

}
